<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getSuiJi() {
            return parseInt(Math.random() * (10 - 1) + 1)
        }
        function game() {
            var n = getSuiJi()
            while (true) {
                var r = prompt("输入数字")
                if (r > n) {
                    alert("猜大了")
                } else if (r < n) {
                    alert("猜小了")
                } else {
                    alert("猜对了！！")
                    break;
                }
            }
        }
        game()

        console.log(getSuiJi());

    </script>
</body>

</html>